package com.jerkin.thread;

import com.alibaba.ttl.threadpool.TtlExecutors;

import org.slf4j.MDC;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @version V1.0
 * @ClassName: TestThread
 * @Description:
 * @author: huhongzhi
 * @date: 2020/10/10 17:19
 */
public class TestThread {

    public static void main(String[] args) {
        AtmoicValue.setInValue("test");
        MDC.put("TEXT","TEXT");
        System.out.println(Thread.currentThread().getName() + ":" + AtmoicValue.getInValue());
        System.out.println(MDC.get("TEXT"));
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService = TtlExecutors.getTtlExecutorService(executorService);
        for(int i=0;i<5;i++){
            executorService.submit(() -> {
                System.out.println(MDC.get("TEXT"));
                AtmoicValue.setInValue("test-"+Thread.currentThread().getName());
                System.out.println((Thread.currentThread().getName() + ":" + AtmoicValue.getInValue()));
            });
        }
        for(int i=0;i<5;i++){
            executorService.submit(() -> {
                System.out.println(MDC.get("TEXT"));
                System.out.println("第二次"+Thread.currentThread().getName() + ":" + AtmoicValue.getInValue());
            });
        }
    }
}
